package com.ymm.websocket.demo.controller;

import com.ymm.websocket.demo.server.WebSocketServer;
import com.ymm.websocket.demo.server.WebSocketServerCustomerHashMap2;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;


/**
 * @Description: TODO
 * @Author: Xuecheng Li
 * @CreateTime: 2022-08-10 11:27
 * @Version: 1.0.0
 */
@Slf4j
@Controller
public class SystemController {
    //页面请求
    @GetMapping("/index/{userId}")
    public ModelAndView socket(@PathVariable String userId) {
        ModelAndView mav = new ModelAndView();
        mav.setViewName("redirect:templates/index.html");
        mav.addObject("userId", userId);
        return mav;
    }

    /**
     * 登录页面
     * @return
     */
    @RequestMapping(value = {"/", "/index", ""}, method = RequestMethod.GET)
    public String index(){


        return "index";
    }


//    //推送数据接口
//    @ResponseBody
//    @RequestMapping("/socket/push/{cid}")
//    public Map pushToWeb(@PathVariable String cid, String message) {
//        log.info("用户：{}发送了消息", cid);
//        Map<String,Object> result = new HashMap<>(10);
//        try {
//            WebSocketServer.sendInfo(message, cid);
//            result.put("code", cid);
//            result.put("msg", message);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return result;
//    }
}
